<template>
    <div class="app-container">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="danger"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    :disabled="multiple"
                    @click="handleDelete"
                >删除
                </el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="序号" align="center" type="index" :index="calculateIndex"/>
            <el-table-column label="订单编号" align="center" prop="orderNo"/>
            <el-table-column label="退款编号" align="center" prop="refundNo"/>
            <el-table-column label="创建时间" align="center" prop="createTime">
                <template v-slot="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="订单金额" align="center" prop="totalFee">
                <template v-slot="scope">
                    <span>{{ scope.row.totalFee / 100 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="申请退款金额" align="center" prop="applyRefund">
                <template v-slot="scope">
                    <span>{{ scope.row.applyRefund / 100 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="退款金额" align="center" prop="refund">
                <template v-slot="scope">
                    <span>{{ scope.row.refund / 100 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="退款原因" align="center" prop="reason"/>
            <el-table-column label="退款状态" align="center" prop="refundStatus"/>
        </el-table>

        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />
    </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { listRefund } from '@/api/order/refund'

import '@/utils/directives.js'

export default {
    name: 'Gateway',
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            orderList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {}
        }
    },
    components: {},
    created() {
        this.getList()
    },
    computed: {
        ...mapGetters([
            'projectList'
        ])
    },
    methods: {
        calculateIndex(index) {
            const pageNum = this.queryParams.pageNum
            const pageSize = this.queryParams.pageSize
            return index + 1 + (pageNum - 1) * pageSize
        },
        getList() {
            this.loading = true
            listRefund(this.queryParams).then(response => {
                this.orderList = response.rows
                this.total = response.total
                this.loading = false
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {}
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm')
            this.handleQuery()
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.gatewayId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset()
            this.open = true
            this.title = '添加网关'
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
        },
        /** 提交按钮 */
        submitForm() {
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const gatewayIds = row.gatewayId || this.ids
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('system/gateway/export', {
                ...this.queryParams
            }, `gateway_${new Date().getTime()}.xlsx`)
        }

    }
}
</script>
